package com.example.hasee.zhcd.Activities.ShangWu;

import android.graphics.Bitmap;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.example.hasee.zhcd.Activities.ChuanWu.MakePicActivity;
import com.example.hasee.zhcd.Adapters.SfygDetailAdapter;
import com.example.hasee.zhcd.Base.BaseActivity;
import com.example.hasee.zhcd.Bean.EventMsg;
import com.example.hasee.zhcd.R;
import com.example.hasee.zhcd.Util.ProgressDialogUtils;
import com.example.hasee.zhcd.View.NoScrollListView;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;

public class FMDetailActivity extends BaseActivity {
    private RelativeLayout picLayout;
    private TextView title;
    private ImageView back;
    private ImageView home;
    private ArrayList<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();
    private NoScrollListView listView;
    private SfygDetailAdapter adapter;
    private TextView date;
    private int mYear;
    private int mMonth;
    private int mDay;
    private Bitmap bitmap;
    private String strSYN;

    @Override
    public int contentViewId() {
        return R.layout.activity_sfyg_pictrue;
    }

    @Override
    public void set() {
        final Calendar c = Calendar.getInstance();
        mYear = c.get(Calendar.YEAR);
        mMonth = c.get(Calendar.MONTH) + 1;
        mDay = c.get(Calendar.DAY_OF_MONTH);
        title.setText("使费预估详情");
        back.setOnClickListener(this);
//        home.setImageResource(R.mipmap.edit);
//        home.setOnClickListener(this);
        home.setVisibility(View.INVISIBLE);
        date.setText(mYear + "-" + mMonth + "-" + mDay);
        getSFYGDetail();
    }

    @Override
    public void init() {
        strSYN = getIntent().getExtras().getString("strSYN");
        back = (ImageView) findViewById(R.id.back);
        home = (ImageView) findViewById(R.id.home);
        title = (TextView) findViewById(R.id.centertitle);
        picLayout = (RelativeLayout) findViewById(R.id.takepic);
        listView = (NoScrollListView) findViewById(R.id.fylist);
        date = (TextView) findViewById(R.id.dateriqi);
    }

    private void getSFYGDetail() {
        ProgressDialogUtils.createProgressDialog(FMDetailActivity.this, "正在获取数据...");
        HashMap<String, String> map = new HashMap<String, String>();
        map.put("strSYN", strSYN);
        httpUtils.get("ZHSW_zgcb_SFYGDetail", map, "ZHSW_zgcb_SFYGDetail");
    }

    @Override
    public void getEventData(EventMsg msg) {
        switch (msg.getAction()) {
            case "Fail":
                ProgressDialogUtils.closeProgressDialog();
                Toast.makeText(FMDetailActivity.this, "操作失败，请检查网络！", Toast.LENGTH_LONG).show();
                break;
            case "ZHSW_zgcb_SFYGDetail":
                ProgressDialogUtils.closeProgressDialog();
                try {
                    JSONObject json = new JSONObject(msg.getMsg());
                    String rspcode = json.getString("rspcode");
                    String rspmessage = json.getString("rspcode");
                    if ("0".equals(rspcode)) {
                        JSONArray data = json.getJSONArray("data");
                        for (int i = 0; i < data.length(); i++) {
                            HashMap<String, String> map = new HashMap<String, String>();
                            map.put("fnote", data.getJSONObject(i).getString("fnote"));
                            list.add(map);
                        }
                        adapter = new SfygDetailAdapter(FMDetailActivity.this, list);
                        listView.setAdapter(adapter);
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
                break;
        }
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.back:
                finish();
                break;
        }
    }
}
